package com.pureut.storage.service.impl;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.exception.GlobalException;
import com.pureut.common.core.utils.StringUtils;
import com.pureut.common.core.utils.bean.BeanUtils;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.datascope.annotation.DataScope;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.common.security.utils.SecurityUtils;
import com.pureut.production.api.FeignProductionService;
import com.pureut.production.api.domain.FeedRecord;
import com.pureut.production.api.domain.LineStock;
import com.pureut.storage.domain.*;
import com.pureut.storage.domain.system.domain.SysDocument;
import com.pureut.storage.dto.*;
import com.pureut.storage.export.ProductionPickingExport;
import com.pureut.storage.mapper.*;
import com.pureut.storage.service.*;
import com.pureut.storage.utils.DocumentTypeEnum;
import com.pureut.storage.utils.GenerationMethodEnum;
import com.pureut.storage.vo.*;
import com.pureut.system.api.FeignService;
import com.pureut.system.api.QualityFeginService;
import com.pureut.system.api.RemoteUserService;
import com.pureut.system.api.SystemDocumentFeignService;
import com.pureut.system.api.domain.SysDictData;
import com.pureut.system.api.domain.SysUser;
import com.pureut.system.api.vo.MaterialNumberAndBatchNoVo;
import com.pureut.system.api.vo.QualityInspectionDocumentVo;
import com.pureut.system.api.vo.QualitySchemeConfigurationVo;
import com.pureut.system.api.vo.UpdateQualityStatusVo;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 生产领料控制层
 *
 * @author: CM
 * @date: 2022/12/23  13:46
 */
@Service
public class ProductionPickingServiceImpl extends ServiceImpl<ProductionPickingMapper, StockOutInfo> implements ProductionPickingService {

    @Lazy
    @Resource
    ProductionPickingMapper productionPickingMapper;

    @Resource
    FeignService feignService;

    @Resource
    WarehouseMapper warehouseMapper;

    //库存
    @Resource
    WmsStockInfoMapper wmsStockInfoMapper;

    @Resource
    private StockOutInfoDetailMapper stockOutInfoDetailMapper;

    @Resource
    private StockInfoDetailService stockInfoDetailService;

    //单据配置
    @Resource
    private SystemDocumentFeignService systemDocumentFeignService;

    //员工信息
    @Resource
    private RemoteUserService remoteUserService;

    //仓库建模
    @Resource
    private WmsStockInfoService wmsStockInfoService;

    //公共物料
    @Resource
    private PublicGoodsMapper publicGoodsMapper;

    //拣货提示
    @Resource
    private PickingSchemeService pickingSchemeService;

    //品质检验
    @Resource
    private QualityFeginService qualityFeginService;

    @Lazy
    @Resource
    private PickingOutsourceService pickingOutsourceService;

    @Lazy
    @Resource
    private PickingSaleService pickingSaleService;

    @Lazy
    @Resource
    private PickingCompleteService pickingCompleteService;

    @Lazy
    @Resource
    private PickingPurchaseService pickingPurchaseService;

    @Lazy
    @Resource
    private PickingReturnsService pickingReturnsService;

    @Lazy
    @Resource
    private PickingRestService pickingRestService;

    @Resource
    private FeignProductionService feignProductionService;

    @Resource
    private AllotManagementService allotManagementService;

    @Resource
    private OutboundLogMapper outboundLogMapper;

    @Resource
    private OutboundLogService outboundLogService;


    /**
     * 新增生产领料单
     *
     * @param productionPickingVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addProductionPicking(ProductionPickingVo productionPickingVo) throws Exception {
        List<ProductionPickingRelationVo> list = productionPickingVo.getList();



        List<StockOutInfo> productionPickinglist = new ArrayList<>();
        if (list.size() > 0) {

            for (ProductionPickingRelationVo productionPickingRelationVo : list) {
                StockOutInfo stockOutInfo = new StockOutInfo();
                BeanUtils.copyProperties(productionPickingVo, stockOutInfo);
                BeanUtils.copyProperties(productionPickingRelationVo, stockOutInfo);

                AjaxResult ajaxResult = feignService.getModelingLineInfo(productionPickingVo.getProductionLine());
                SysLineDto sysLineDto = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), SysLineDto.class);

                String sn = feignService.getAuthorityCoding("warehouse:outbound:producfield:list");
                if (sn == null) {
                    throw new GlobalException("该单据未进行配置,无法生成单据编码");
                }

                stockOutInfo.setCreateUser(SecurityUtils.getUsername())
                        .setCreateTime(new Date())
                        .setProductionLineName(sysLineDto.getLineName())
                        .setDocumentType(DocumentTypeEnum.PRODUCTION_PICKING.getCode())
                        .setWodDocNum(sn)
                        .setDeptId(SecurityUtils.getDeptId())
                        .setWodStatus(1)
                        .setGenerationMode(GenerationMethodEnum.MANUALLY_GENERATED.getCode());
                productionPickinglist.add(stockOutInfo);
/*
                String moNumber = productionPickingRelationVo.getMoNumber();

                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfo.getMaterialCode()));
                if((moNumber.contains("SC"))) {
                boolean b = feignProductionService.getInfo(stockOutInfo.getMoNumber());
                    if (!b) {
                        FeedRecord feedRecord = new FeedRecord();
                        feedRecord.setFeedOrderNumber(stockOutInfo.getMoNumber());
                        feedRecord.setLineCode(productionPickingVo.getProductionLine());
                        feedRecord.setMaterialCode(stockOutInfo.getMaterialCode());
                        feedRecord.setMaterialName(publicGoods.getMaterialName());
                        feedRecord.setMaterialSpec(publicGoods.getMaterialSpec());
                        feedRecord.setDeliveryWeight(stockOutInfo.getPlannedWeight());
                        feedRecord.setInvestedWeight(0);
                        feedRecord.setFeedType("1");
                        feedRecord.setCreateBy(SecurityUtils.getUsername());
                        AjaxResult add = feignProductionService.add(feedRecord);
                    }
                }*/
            }

            return saveBatch(productionPickinglist);
        } else {
            throw new GlobalException("请至少添加一条物料明细");
        }

    }

    /**
     * 查询生产领料单列表
     *
     * @param productionPickingVo
     * @return
     */
    @Override
    @DataScope(deptAlias = "t1")
    public List<StockOutInfoDto> getList(ProductionPickingVo productionPickingVo) {
        List<StockOutInfoDto> stockOutInfos = productionPickingMapper.getproductionPickingList(productionPickingVo);

        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("stock_out_info_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        //根据字典查出收发类型
        List<SysDictData> receivType = DictUtils.getDictCache("stock_out_info_type");
        Map<String, String> typeMap = receivType.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //根据字典查出单位
        List<SysDictData> unitList = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unitList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (StockOutInfoDto stockOutInfoDto : stockOutInfos) {

            //添加单据状态
            stockOutInfoDto.setWodStatusDict(stockOutInfoDto.getWodStatus() + "");
            stockOutInfoDto.setWodStatus(statusMap.get(stockOutInfoDto.getWodStatus() + ""));

            //添加领用产线


            //查看仓库名称
            Warehouse warehouse = warehouseMapper.selectById(stockOutInfoDto.getOutOfStock());
            if (warehouse != null) {
                //添加仓库名称
                stockOutInfoDto.setOutOfStock(warehouse.getWarehouseName());
            }
            //添加单位key
            stockOutInfoDto.setMaterialUnitDict(stockOutInfoDto.getMaterialUnit() + "");
            //添加单位值
            stockOutInfoDto.setMaterialUnit(unitMap.get(stockOutInfoDto.getMaterialUnit() + ""));

            //添加单据类型
            stockOutInfoDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(stockOutInfoDto.getDocumentType())));

            //添加收发类型
            stockOutInfoDto.setTransceiverTypeDict(stockOutInfoDto.getTransceiverType() + "");
            stockOutInfoDto.setTransceiverType(typeMap.get(stockOutInfoDto.getTransceiverType() + ""));

            //制令单
            stockOutInfoDto.setProductionLine(stockOutInfoDto.getProductionLineName());

            //添加生产方式
            stockOutInfoDto.setGenerationMode(GenerationMethodEnum.getValue(Integer.parseInt(stockOutInfoDto.getGenerationMode())));
        }
        return stockOutInfos;
    }


    /**
     * 查询生产领料单列表Pda
     *
     * @param productionPickingVo
     * @return
     */
    @DataScope(deptAlias = "t1")
    public List<GetPdaDto> getListPda(ProductionPickingVo productionPickingVo) {
        List<GetPdaDto> list = productionPickingMapper.getproductionPickingListPda(productionPickingVo);

        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("stock_out_info_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (GetPdaDto getPdaDto : list) {
            getPdaDto.setWodStatusDict(statusMap.get(getPdaDto.getWodStatus()));
        }

        return list;
    }


    /**
     * 生产确认
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean confirm(Long id) {
        //查询当前id的状态
        StockOutInfo stockOutInfo = getOne(new QueryWrapper<StockOutInfo>().lambda().select(StockOutInfo::getWodStatus).eq(StockOutInfo::getId, id));
        //获取当前状态
        int wodStatus = stockOutInfo.getWodStatus();
        if (wodStatus != 1) {
            throw new GlobalException("只能对状态为“待确认”的单据进行生产确认");
        }
        //修改单据状态为待出库
        StockOutInfo update = new StockOutInfo();
        update.setId(id);
        update.setWodStatus(2);
        return updateById(update);
    }

    /**
     * 修改单据
     *
     * @param productionPickingVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateDoc(ProductionPickingVo productionPickingVo) {
        //查询当前id对应的单据
        StockOutInfo stockOutInfo = productionPickingMapper.selectById(productionPickingVo.getId());
        //获取当前单据状态
        int wodStatus = stockOutInfo.getWodStatus();
        if (wodStatus != 1) {
            throw new GlobalException("只能对状态为“待确认”的单据进行修改");
        }

        //设置修改的值
        //领用产线
        stockOutInfo.setProductionLine(productionPickingVo.getProductionLine());
        //收发类型
        stockOutInfo.setTransceiverType(productionPickingVo.getTransceiverType());
        //出库日期
        stockOutInfo.setDateDelivery(productionPickingVo.getDateDelivery());
        //备注
        stockOutInfo.setRemark(productionPickingVo.getRemark());

        List<ProductionPickingRelationVo> list = productionPickingVo.getList();
        ProductionPickingRelationVo productionPickingRelationVo = list.get(0);
        stockOutInfo.setMoNumber(productionPickingVo.getMoNumber());
        stockOutInfo.setPlannedWeight(productionPickingRelationVo.getPlannedWeight());
        stockOutInfo.setOutOfStock(productionPickingRelationVo.getOutOfStock());
        return updateById(stockOutInfo);

    }

    /**
     * 查看物料信息
     *
     * @param id
     * @return
     */
    @Override
    public StockOutInfoDto view(Long id) {
        StockOutInfoDto stockOutInfoDto = productionPickingMapper.getproductionPickingLById(id);

        //根据字典查出单位
        List<SysDictData> unitList = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unitList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //添加单据类型
        stockOutInfoDto.setDocumentTypeDict(DocumentTypeEnum.getValue(Integer.parseInt(stockOutInfoDto.getDocumentType())));
        stockOutInfoDto.setDocumentType(stockOutInfoDto.getDocumentType());

        //根据字典查出收发类型
        List<SysDictData> receivType = DictUtils.getDictCache("stock_out_info_type");
        Map<String, String> typeMap = receivType.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //添加收发类型
        stockOutInfoDto.setTransceiverType(stockOutInfoDto.getTransceiverType() + "");
        stockOutInfoDto.setTransceiverTypeDict(typeMap.get(stockOutInfoDto.getTransceiverType() + ""));
        //定义查看明细列表
        List<ProductionPickingViewDto> list = new ArrayList<>();

        ProductionPickingViewDto productionPickingViewDto = new ProductionPickingViewDto();


        //根据仓库id查出仓库名称
        if (stockOutInfoDto.getOutOfStock()!=null){
            Warehouse warehouse = warehouseMapper.selectById(stockOutInfoDto.getOutOfStock());
            //添加仓库名称
            productionPickingViewDto.setOutOfStockDict(warehouse.getWarehouseName());
            productionPickingViewDto.setOutOfStock(stockOutInfoDto.getOutOfStock() + "");
        }


        //添加单位key
        productionPickingViewDto.setMaterialUnit(stockOutInfoDto.getMaterialUnit() + "");
        //添加单位值
        productionPickingViewDto.setMaterialUnitDict(unitMap.get(stockOutInfoDto.getMaterialUnit() + ""));

        //添加物料名称,物料编码,物料规格
        productionPickingViewDto.setMaterialCode(stockOutInfoDto.getMaterialCode());
        productionPickingViewDto.setMaterialName(stockOutInfoDto.getItemName());
        productionPickingViewDto.setMaterialSpec(stockOutInfoDto.getItemSpec());

        //添加计划量
        productionPickingViewDto.setPlannedWeight(stockOutInfoDto.getPlannedWeight());

        //制令单
        productionPickingViewDto.setMoNumber(stockOutInfoDto.getMoNumber());

        list.add(productionPickingViewDto);
        stockOutInfoDto.setList(list);
        return stockOutInfoDto;
    }

    /**
     * 删除单据
     *
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteDoc(String ids) {
        //将ids根据逗号拆分成数组
        List<String> idStr = Arrays.asList(ids.split(","));
        if (idStr.size() == 0) {
            throw new GlobalException("请至少勾选一条单据");
        }
        //根据ids批量查询出list列表
        List<StockOutInfo> stockOutInfos = productionPickingMapper.selectBatchIds(idStr);

        //遍历
        for (StockOutInfo stockOutInfo : stockOutInfos) {
            if (stockOutInfo.getWodStatus() != 1) {
                throw new GlobalException("只能删除待确认下的单据");
            } else if (stockOutInfo.getGenerationMode() != 2) {
                throw new GlobalException("系统自动生成的单据不可删除");
            }
        }
        return removeBatchByIds(idStr);

    }

    /**
     * 关结单据
     *
     * @param productionPickingVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean closeDoc(ProductionPickingVo productionPickingVo) {

        //查询是否有关联单据，如果有则关结单据

        StockOutInfo stockOutInfo = getById(productionPickingVo.getId());
        int status = stockOutInfo.getWodStatus();

        if (status==6||status==7){
            throw new GlobalException("不可对已关结和已完成状态的单据进行重复关结");
        }


        try {

            //批量新增线边仓的数据
            //根据单号获取生产领料单明细
            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

            ArrayList<LineStock> lineStockList = new ArrayList<>();

            for (StockOutInfoDetail stock : stockOutInfoDetailList) {

                WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stock.getMaterialNumber()));

                //往线边仓新增数据
                LineStock lineStock = new LineStock();
                lineStock.setMaterialNumber(stock.getMaterialNumber());
                if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                    lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                }
                lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                lineStock.setIntoTheTime(new Date());
                lineStock.setLineCode(stockOutInfo.getProductionLine());
                lineStock.setFreezeMark(2);

                lineStockList.add(lineStock);
            }

            if (lineStockList.size()!=0){
                AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                if (!"200".equals(ajaxResult.get("code").toString())){
                    throw new GlobalException("操作异常");
                }
            }

            //如果单据状态是待检验，入库的物料显示在库，关联品质检验单状态更新为撤销
            if(status==4||status==5||status==3){

                ArrayList<WmsStockInfo> wmsStockInfos = new ArrayList<>();

                for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetailList) {
                    WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                    wmsStockInfos.add(wmsStockInfo);
                }

                if (wmsStockInfos.size()!=0){
                    boolean b = wmsStockInfoService.removeBatchByIds(wmsStockInfos);
                }


                if (status==4){
                    //如果是待检验删除品质检验单
                    UpdateQualityStatusVo updateQualityStatusVo = new UpdateQualityStatusVo();
                    updateQualityStatusVo.setStatus(8);
                    updateQualityStatusVo.setAssociatedNo(stockOutInfo.getWodDocNum());
                    AjaxResult ajaxResult = qualityFeginService.updateQualityInspectionDocument(updateQualityStatusVo);


                    if (!"200".equals(ajaxResult.get("code").toString())){
                        throw new GlobalException("服务调用失败");
                    }

                }
            }



        }catch (Exception e){
            throw new GlobalException("关结失败");
        }


        //取出关结人
        String closeMan = stockOutInfo.getCloseMan();
        if (closeMan!=null){
            closeMan=closeMan+","+SecurityUtils.getUsername();
        }else{
            closeMan=SecurityUtils.getUsername();
        }

        stockOutInfo.setId(productionPickingVo.getId())
                .setWodStatus(7).setCloseTime(new Date())
                .setCloseMan(closeMan)
                .setCloseCause(productionPickingVo.getCloseCause());
        return updateById(stockOutInfo);
    }

    /**
     * 导出
     *
     * @param productionPickingVo
     * @return
     */
    @Override
    public List<ProductionPickingExport> getInfoExport(ProductionPickingVo productionPickingVo) {


        //获取ids
        String idStr = productionPickingVo.getIdStr();

        if (idStr!=null) {

            List<String> idList = Arrays.asList(idStr.split(","));
            productionPickingVo.setIds(idList);
        }

        List<ProductionPickingExport> list = productionPickingMapper.getInfoExport(productionPickingVo);

        //根据字典查出收发类型
        List<SysDictData> receivType = DictUtils.getDictCache("stock_out_info_type");
        Map<String, String> typeMap = receivType.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (ProductionPickingExport pickingExport : list) {
            pickingExport.setTransceiverTypeDict(typeMap.get(pickingExport.getTransceiverTypeDict()));
        }

        return list;
    }

    /**
     * Pda出库
     *
     * @param pickingRestDbVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public PickingRestDbDto out(PickingRestDbVo pickingRestDbVo) throws Exception {
        //出库类型
        String type = pickingRestDbVo.getType();
        //输入值
        String inputValue = pickingRestDbVo.getInputValue();

        PickingRestDbDto pickingRestDbDto = new PickingRestDbDto();

        //根据字典查出单位
        List<SysDictData> unitList = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unitList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //判断是否超收或者超发
        //获取菜单id
        Long menuId = feignService.getIdByMenuName("生产领料");
        AjaxResult infoDocumentConfigById = systemDocumentFeignService.getInfoDocumentConfigById(menuId);
        SysDocument sysDocument = JSON.parseObject(JSON.toJSONString(infoDocumentConfigById.get("data")), SysDocument.class);

        StockOutInfo stockOutInfoInfo = getById(pickingRestDbVo.getId());
        PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfoInfo.getMaterialCode()));

        //如果配置了送检,则校验是否配了检验方案
        if (sysDocument.getDocInspectionMark()==1){

            List<SysDocumentCheckDto> documentCheckDtoList = sysDocument.getDocumentCheckDtoList();
            if (documentCheckDtoList==null){
                throw new GlobalException("请先在单据配置中配置送检方案");
            }



            StockOutInfo byId = getById(pickingRestDbVo.getId());
            QualitySchemeConfigurationVo qualitySchemeConfigurationVo = new QualitySchemeConfigurationVo();
            qualitySchemeConfigurationVo.setCategory(publicGoods.getMaterialCategory());
            qualitySchemeConfigurationVo.setItemRank(documentCheckDtoList.get(0).getCheckSubmit());
            qualitySchemeConfigurationVo.setMaterialCategory(publicGoods.getMaterialType());
            qualitySchemeConfigurationVo.setMaterialCode(byId.getMaterialCode());
            boolean check = qualityFeginService.check(qualitySchemeConfigurationVo);

            if (!check){
                throw new GlobalException("该物料不存在对应的检验方案");

            }
        }

        //如果是扫码出库
        if ("1".equals(type)) {
            //判断扫描的物料条码是否一致
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue).eq(WmsStockInfo::getWsiMaterialStatus, 2));
            if (wmsStockInfo == null) {
                pickingRestDbDto.setMessage("扫描失败，请核实后扫描");
                pickingRestDbDto.setCode("500");
                return pickingRestDbDto;
            }

            if ("1".equals(wmsStockInfo.getWsiFreezeInfo())) {
                throw new GlobalException("此物料已冻结请重新输入");
            }

            //扫描的物料编码
            String wsiMaterialCode = wmsStockInfo.getWsiMaterialCode();
            //查询生产领料单中的物料编码
            StockOutInfo stockOutInfo = productionPickingMapper.selectById(pickingRestDbVo.getId());

            if (!stockOutInfo.getMaterialCode().equals(wsiMaterialCode)) {
                pickingRestDbDto.setMessage("扫描失败，请核实后扫描");
                pickingRestDbDto.setCode("500");
                return pickingRestDbDto;
            }

            //判断是否重复扫描(在明细表中查询是否有该条码)
            StockOutInfoDetail stockOutInfoDetail1 = stockOutInfoDetailMapper.selectOne(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getMaterialNumber, inputValue).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
            if (stockOutInfoDetail1 != null) {
                pickingRestDbDto.setMessage("请勿重复扫描");
                pickingRestDbDto.setCode("500");
                return pickingRestDbDto;
            }

            StockOutInfoDetail stockOutInfoDetail = new StockOutInfoDetail();

            //物料号码
            stockOutInfoDetail.setMaterialNumber(inputValue);

            //物料状态
            stockOutInfoDetail.setStatus("3");

            //物料编码
            stockOutInfoDetail.setMaterialCode(stockOutInfo.getMaterialCode());

            //关联单号
            stockOutInfoDetail.setWodDocNum(stockOutInfo.getWodDocNum());

            //毛重
            stockOutInfoDetail.setGrossWeight(wmsStockInfo.getWsiGorssWeight());

            //净重
            stockOutInfoDetail.setTheWeight(wmsStockInfo.getWsiNetWeight());

            //出库数量
            stockOutInfoDetail.setOutgoingNumber(wmsStockInfo.getWsiMaterialNum());

            //批次号
            stockOutInfoDetail.setBatchNumber(wmsStockInfo.getWsiMaterialBatch());

            //供应商编码
            stockOutInfoDetail.setSupplierCode(wmsStockInfo.getWsiSupplierCode());

            //仓储信息
            stockOutInfoDetail.setWarehouseInfo(wmsStockInfo.getWsiWarehourseInfo());

            //出库人
            stockOutInfoDetail.setDepositor(SecurityUtils.getUsername());

            //出库时间
            stockOutInfoDetail.setDeliveryTime(new Date());


            //判断是否有检验
            int docInspectionMark = sysDocument.getDocInspectionMark();
            //如果有检验
            if (docInspectionMark == 1) {
                //修改单据明细为待检验
                stockOutInfoDetail.setStatus("1");
            } else {
                //判断是否有交接
                int docHandoverMark = sysDocument.getDocHandoverMark();
                //有交接
                if (docHandoverMark == 1) {
                    //修改单据明细为待交接
                    stockOutInfoDetail.setStatus("2");

                }
            }
            //添加明细
            stockOutInfoDetailMapper.insert(stockOutInfoDetail);

            //修改生产领料单的单据状态为出库中
            stockOutInfo.setWodStatus(3);
            //修改出库重量和出库数量
            BigDecimal bigDecimal = new BigDecimal(String.valueOf(stockOutInfo.getOutgoingWeight()));
            BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(wmsStockInfo.getWsiNetWeight()));

            BigDecimal add = bigDecimal.add(bigDecimal1);
            stockOutInfo.setOutgoingWeight(add.doubleValue());
            stockOutInfo.setOutgoingNumber(stockOutInfo.getOutgoingNumber() + 1);

            //判断单位是否是kg
            if ("2".equals(publicGoods.getMaterialUnit())) {
                //实际量
                stockOutInfo.setActualNumber(stockOutInfo.getOutgoingWeight());
            }else if("3".equals(publicGoods.getMaterialUnit())){
                //实际量
                BigDecimal dun = new BigDecimal("1000");
                BigDecimal outNum = new BigDecimal(String.valueOf(stockOutInfo.getOutgoingWeight()));
                BigDecimal divide = outNum.divide(dun);
                stockOutInfo.setActualNumber(divide.doubleValue());
            }else {
                //实际量
                stockOutInfo.setActualNumber(Double.parseDouble(stockOutInfo.getOutgoingNumber() + ""));
            }
            updateById(stockOutInfo);

            //修改仓库物料的状态为备料
            wmsStockInfo.setWsiMaterialStatus(5);
            int i = wmsStockInfoMapper.updateById(wmsStockInfo);


            //返回前端参数
            //计划/实际
            pickingRestDbDto.setQuantityIdentification(stockOutInfo.getPlannedWeight() + "/" + stockOutInfo.getActualNumber() + unitMap.get(publicGoods.getMaterialUnit()));
            //出库数量
            pickingRestDbDto.setAllotNumOut(stockOutInfo.getOutgoingNumber() + "");

            pickingRestDbDto.setMessage("物料号码:" + inputValue + ",净重:" + wmsStockInfo.getWsiNetWeight() + ",数量:1" + "录入成功");
            pickingRestDbDto.setCode("200");

            OutboundLog outboundLog = new OutboundLog();
            BeanUtils.copyProperties(wmsStockInfo,outboundLog,new String[]{"id"});
            outboundLogService.save(outboundLog);
            pickingRestDbDto.setPickingPrompt(point(stockOutInfo.getId()).getCombinationName());

            //查询当前生产领料单
            StockOutInfo stockOutInfo1 = productionPickingMapper.selectById(pickingRestDbVo.getId());
            //判断是否有超收
            int docHairMark = sysDocument.getDocHairMark();
            //没有超发
            if (docHairMark != 1 && publicGoods.getMaterialHair() != 1) {

                //如果是kg
                if ("2".equals(publicGoods.getMaterialUnit())||"3".equals(publicGoods.getMaterialUnit())) {
                    //计划出库重量
                    Double allotAmount = stockOutInfo1.getPlannedWeight();
                    //实际出库重量
                    Double allotWeightOut = stockOutInfo1.getActualNumber();
                    if (allotWeightOut >= allotAmount) {
                        //判断是否有检验或者交接
                        //判断是否有检验
                        int isDocInspectionMark = sysDocument.getDocInspectionMark();
                        //如果有检验
                        if (isDocInspectionMark == 1) {
                            //生成品质检验单
                            QualityInspectionDocumentVo qualityInspectionDocumentVo = new QualityInspectionDocumentVo();
                            //添加类别，编码，物料类别
                            qualityInspectionDocumentVo.setMaterialCode(stockOutInfo.getMaterialCode());
                            qualityInspectionDocumentVo.setMaterialCategory(publicGoods.getMaterialType());
                            qualityInspectionDocumentVo.setCategory(publicGoods.getMaterialCategory());
                            qualityInspectionDocumentVo.setAssociatedNo(stockOutInfo.getWodDocNum());
                            qualityInspectionDocumentVo.setModeType(1);
                            List<MaterialNumberAndBatchNoVo> materialNumberAndBatchNoVos = new ArrayList<>();
                            //查询当前明细表中的所有物料号码
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                            String batchNum = "";

                            for (int j = 0; j < stockOutInfoDetailList.size(); j++) {
                                if (j == 0) {
                                    batchNum = stockOutInfoDetailList.get(j).getBatchNumber();
                                } else {
                                    if (!batchNum.equals(stockOutInfoDetailList.get(j).getBatchNumber())) {
                                        batchNum = batchNum + "," + stockOutInfoDetailList.get(j).getBatchNumber();
                                    }
                                }

                                MaterialNumberAndBatchNoVo materialNumberAndBatchNoVo = new MaterialNumberAndBatchNoVo();
                                materialNumberAndBatchNoVo.setMaterialNumber(stockOutInfoDetailList.get(j).getMaterialNumber());
                                materialNumberAndBatchNoVo.setBatchNo(stockOutInfoDetailList.get(j).getBatchNumber());
                                materialNumberAndBatchNoVo.setMaterialCategory(publicGoods.getMaterialCategory());
                                materialNumberAndBatchNoVos.add(materialNumberAndBatchNoVo);
                            }
                            qualityInspectionDocumentVo.setBatchNo(batchNum);

                            insertQuality(sysDocument, qualityInspectionDocumentVo, materialNumberAndBatchNoVos);
                            //修改单据为待检验
                            stockOutInfo1.setWodStatus(4);
                            productionPickingMapper.updateById(stockOutInfo1);
                            return pickingRestDbDto;
                        }
                        //判断是否有交接
                        int docHandoverMark = sysDocument.getDocHandoverMark();
                        //有交接
                        if (docHandoverMark == 1) {
                            //修改单据为待交接
                            stockOutInfo1.setWodStatus(5);
                            productionPickingMapper.updateById(stockOutInfo1);

                        } else {
                            //修改单据为yiwanc
                            stockOutInfo1.setWodStatus(6);

                            List<LineStock> lineStockList = new ArrayList<>();
                            //新增线边仓数据
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                            for (StockOutInfoDetail outInfoDetail : stockOutInfoDetailList) {

                                //查询仓库中的数据
                                WmsStockInfo wmsStockInfo11 = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, outInfoDetail.getMaterialNumber()));

                                //往线边仓新增数据
                                LineStock lineStock = new LineStock();
                                lineStock.setMaterialNumber(outInfoDetail.getMaterialNumber());
                                if (!StringUtils.isEmpty(wmsStockInfo11.getWsiMaterialGrade())) {
                                    lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo11.getWsiMaterialGrade()));
                                }
                                lineStock.setMaterialCode(wmsStockInfo11.getWsiMaterialCode());
                                lineStock.setStockBatch(wmsStockInfo11.getWsiMaterialBatch());
                                lineStock.setGrossWeight(wmsStockInfo11.getWsiGorssWeight());
                                lineStock.setNetWeight(wmsStockInfo11.getWsiNetWeight());
                                lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                                lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                                lineStock.setIntoTheTime(new Date());
                                lineStock.setLineCode(stockOutInfo.getProductionLine());
                                lineStock.setFreezeMark(2);

                                lineStockList.add(lineStock);

                            }

                            AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                            if (!"200".equals(ajaxResult.get("code").toString())){
                                throw new GlobalException("出库操作异常");
                            }


                            //删除库存
                            wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue));
                            productionPickingMapper.updateById(stockOutInfo1);
                        }
                    }
                } else {
                    //计划出库重量
                    double allotAmount = stockOutInfo1.getPlannedWeight();
                    //实际出库数量
                    int allotNumOut = stockOutInfo1.getOutgoingNumber();
                    if (allotNumOut >= allotAmount) {
                        //判断是否检验或者交接
                        //判断是否有检验
                        int isDocInspectionMark = sysDocument.getDocInspectionMark();
                        //如果有检验
                        if (isDocInspectionMark == 1) {
                            //生成品质检验单
                            QualityInspectionDocumentVo qualityInspectionDocumentVo = new QualityInspectionDocumentVo();
                            //添加类别，编码，物料类别
                            qualityInspectionDocumentVo.setMaterialCode(stockOutInfo.getMaterialCode());
                            qualityInspectionDocumentVo.setMaterialCategory(publicGoods.getMaterialType());
                            qualityInspectionDocumentVo.setCategory(publicGoods.getMaterialCategory());
                            qualityInspectionDocumentVo.setAssociatedNo(stockOutInfo.getWodDocNum());
                            qualityInspectionDocumentVo.setModeType(1);
                            List<MaterialNumberAndBatchNoVo> materialNumberAndBatchNoVos = new ArrayList<>();
                            //查询当前明细表中的所有物料号码
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                            String batchNum = "";

                            for (int j = 0; j < stockOutInfoDetailList.size(); j++) {
                                if (j == 0) {
                                    batchNum = stockOutInfoDetailList.get(j).getBatchNumber();
                                } else {
                                    if (!batchNum.equals(stockOutInfoDetailList.get(j).getBatchNumber())) {
                                        batchNum = batchNum + "," + stockOutInfoDetailList.get(j).getBatchNumber();
                                    }
                                }

                                MaterialNumberAndBatchNoVo materialNumberAndBatchNoVo = new MaterialNumberAndBatchNoVo();
                                materialNumberAndBatchNoVo.setMaterialNumber(stockOutInfoDetailList.get(j).getMaterialNumber());
                                materialNumberAndBatchNoVo.setBatchNo(stockOutInfoDetailList.get(j).getBatchNumber());
                                materialNumberAndBatchNoVo.setMaterialCategory(publicGoods.getMaterialCategory());
                                materialNumberAndBatchNoVos.add(materialNumberAndBatchNoVo);
                            }
                            qualityInspectionDocumentVo.setBatchNo(batchNum);

                            insertQuality(sysDocument, qualityInspectionDocumentVo, materialNumberAndBatchNoVos);
                            //修改单据为待检验
                            stockOutInfo1.setWodStatus(4);
                            productionPickingMapper.updateById(stockOutInfo1);
                            return pickingRestDbDto;
                        }
                        //判断是否有交接
                        int docHandoverMark = sysDocument.getDocHandoverMark();
                        //有交接
                        if (docHandoverMark == 1) {
                            //修改单据明细为待交接
                            stockOutInfo1.setWodStatus(5);
                            productionPickingMapper.updateById(stockOutInfo1);

                        } else {
                            //修改单据状态为已完成
                            stockOutInfo1.setWodStatus(6);

                            List<LineStock> lineStockList = new ArrayList<>();
                            //新增线边仓数据
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                            for (StockOutInfoDetail outInfoDetail : stockOutInfoDetailList) {

                                //查询仓库中的数据
                                WmsStockInfo wmsStockInfo11 = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, outInfoDetail.getMaterialNumber()));

                                //往线边仓新增数据
                                LineStock lineStock = new LineStock();
                                lineStock.setMaterialNumber(outInfoDetail.getMaterialNumber());
                                if (!StringUtils.isEmpty(wmsStockInfo11.getWsiMaterialGrade())) {
                                    lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                                }
                                lineStock.setMaterialCode(wmsStockInfo11.getWsiMaterialCode());
                                lineStock.setStockBatch(wmsStockInfo11.getWsiMaterialBatch());
                                lineStock.setGrossWeight(wmsStockInfo11.getWsiGorssWeight());
                                lineStock.setNetWeight(wmsStockInfo11.getWsiNetWeight());
                                lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                                lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                                lineStock.setIntoTheTime(new Date());
                                lineStock.setLineCode(stockOutInfo.getProductionLine());
                                lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo11.getWsiFreezeInfo()));

                                lineStockList.add(lineStock);

                            }

                            AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                            if (!"200".equals(ajaxResult.get("code").toString())){
                                throw new GlobalException("出库操作异常");
                            }

                            //删除库存
                            int delete = wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue));
                            productionPickingMapper.updateById(stockOutInfo1);
                        }
                    }
                }
            }

        } else if ("2".equals(type)) {

            List<LineStock> lineStockList = new ArrayList<>();

            //批次出库
            //查询当前批次对应单条码信息
            List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, inputValue).eq(WmsStockInfo::getWsiMaterialStatus, 2).notIn(WmsStockInfo::getWsiFreezeInfo,1));

            if (wmsStockInfoList.size() == 0) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("扫描失败，此批次在仓库中的数量为0");
                return pickingRestDbDto;
            }

            Double netWeight = wmsStockInfoMapper.getNetWeight(inputValue);

            List<StockOutInfoDetail> list = new ArrayList<StockOutInfoDetail>();

            //查询生产领料单中的物料编码、
            StockOutInfo stockOutInfo11 = productionPickingMapper.selectById(pickingRestDbVo.getId());


            List<OutboundLog> outboundLogList = new ArrayList<>();

            for (WmsStockInfo wmsStockInfo : wmsStockInfoList) {


                //扫描的物料编码
                String wsiMaterialCode = wmsStockInfo.getWsiMaterialCode();

                if (!stockOutInfo11.getMaterialCode().equals(wsiMaterialCode)) {
                    pickingRestDbDto.setCode("500");
                    pickingRestDbDto.setMessage("扫描失败，请核实后扫描");

                    return pickingRestDbDto;
                }
                //新增生产领料明细
                StockOutInfoDetail stockOutInfoDetail = new StockOutInfoDetail();
                //物料号码
                stockOutInfoDetail.setMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                //物料状态
                stockOutInfoDetail.setStatus("3");
                //物料编码
                stockOutInfoDetail.setMaterialCode(stockOutInfo11.getMaterialCode());
                //关联单号
                stockOutInfoDetail.setWodDocNum(stockOutInfo11.getWodDocNum());
                //毛重
                stockOutInfoDetail.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                //净重
                stockOutInfoDetail.setTheWeight(wmsStockInfo.getWsiNetWeight());
                //出库数量
                stockOutInfoDetail.setOutgoingNumber(wmsStockInfo.getWsiMaterialNum());
                //批次号
                stockOutInfoDetail.setBatchNumber(wmsStockInfo.getWsiMaterialBatch());
                //供应商编码
                stockOutInfoDetail.setSupplierCode(wmsStockInfo.getWsiSupplierCode());
                //仓储信息
                stockOutInfoDetail.setWarehouseInfo(wmsStockInfo.getWsiWarehourseInfo());
                //出库人
                stockOutInfoDetail.setDepositor(SecurityUtils.getUsername());
                //出库时间
                stockOutInfoDetail.setDeliveryTime(new Date());

                //判断是否有检验
                int docInspectionMark = sysDocument.getDocInspectionMark();
                //如果有检验
                if (docInspectionMark == 1) {
                    //修改单据明细为待检验
                    stockOutInfoDetail.setStatus("1");
                } else {
                    //判断是否有交接
                    int docHandoverMark = sysDocument.getDocHandoverMark();
                    //有交接
                    if (docHandoverMark == 1) {
                        //修改单据明细为待交接
                        stockOutInfoDetail.setStatus("2");

                    }
                }

                //修改出库重量和出库数量
                BigDecimal bigDecimal = new BigDecimal(stockOutInfo11.getOutgoingWeight());
                BigDecimal bigDecimal1 = new BigDecimal(wmsStockInfo.getWsiNetWeight());

                BigDecimal add = bigDecimal.add(bigDecimal1);
                stockOutInfo11.setOutgoingWeight(add.doubleValue());
                stockOutInfo11.setOutgoingNumber(stockOutInfo11.getOutgoingNumber() + 1);

                //添加明细
                list.add(stockOutInfoDetail);

                //修改仓库物料的状态为备料
                wmsStockInfo.setWsiMaterialStatus(5);



                OutboundLog outboundLog = new OutboundLog();
                BeanUtils.copyProperties(wmsStockInfo,outboundLog,new String[]{"id"});

                outboundLogList.add(outboundLog);

            }

            //新增明细
            stockInfoDetailService.saveBatch(list);

            wmsStockInfoService.updateBatchById(wmsStockInfoList);

            //修改生产领料单的单据状态为出库中
            stockOutInfo11.setWodStatus(3);

            //判断单位是否是kg
            if ("2".equals(publicGoods.getMaterialUnit())) {
                //实际量
                stockOutInfo11.setActualNumber(stockOutInfo11.getOutgoingWeight());
            }else if("3".equals(publicGoods.getMaterialUnit())){
                //实际量
                BigDecimal dun = new BigDecimal("1000");
                BigDecimal outNum = new BigDecimal(String.valueOf(stockOutInfo11.getOutgoingWeight()));
                BigDecimal divide = outNum.divide(dun);
                stockOutInfo11.setActualNumber(divide.doubleValue());
            }else {
                //实际量
                stockOutInfo11.setActualNumber(Double.parseDouble(stockOutInfo11.getOutgoingNumber() + ""));
            }
            updateById(stockOutInfo11);


            StockOutInfo stockOutInfo = productionPickingMapper.selectById(pickingRestDbVo.getId());
            //返回前端参数
            //计划/实际
            pickingRestDbDto.setQuantityIdentification(stockOutInfo.getPlannedWeight() + "/" + stockOutInfo.getActualNumber() + unitMap.get(publicGoods.getMaterialUnit()));
            //出库数量
            pickingRestDbDto.setAllotNumOut(stockOutInfo.getOutgoingNumber() + "");


            pickingRestDbDto.setMessage("批次号:" + inputValue + ",总净重:" + netWeight + ",数量:" + wmsStockInfoList.size() + "录入成功");
            pickingRestDbDto.setCode("200");

            outboundLogService.saveBatch(outboundLogList);
            pickingRestDbDto.setPickingPrompt(point(stockOutInfo.getId()).getCombinationName());

            //查询当前生产领料单
            StockOutInfo stockOutInfo1 = productionPickingMapper.selectById(pickingRestDbVo.getId());
            //判断是否有超发
            int docHairMark = sysDocument.getDocHairMark();
            //没有超发
            if (docHairMark != 1 && publicGoods.getMaterialHair() != 1) {

                //如果是kg
                if ("2".equals(publicGoods.getMaterialUnit())||"3".equals(publicGoods.getMaterialUnit())) {
                    //计划出库重量
                    Double allotAmount = stockOutInfo1.getPlannedWeight();
                    //实际出库重量
                    Double allotWeightOut = stockOutInfo1.getActualNumber();
                    if (allotWeightOut >= allotAmount) {
                        //判断是否有检验或者交接
                        //判断是否有检验
                        int isDocInspectionMark = sysDocument.getDocInspectionMark();
                        //如果有检验
                        if (isDocInspectionMark == 1) {
                            //生成品质检验单
                            //生成品质检验单
                            QualityInspectionDocumentVo qualityInspectionDocumentVo = new QualityInspectionDocumentVo();
                            //添加类别，编码，物料类别
                            qualityInspectionDocumentVo.setMaterialCode(stockOutInfo.getMaterialCode());
                            qualityInspectionDocumentVo.setMaterialCategory(publicGoods.getMaterialType());
                            qualityInspectionDocumentVo.setCategory(publicGoods.getMaterialCategory());
                            qualityInspectionDocumentVo.setAssociatedNo(stockOutInfo.getWodDocNum());
                            qualityInspectionDocumentVo.setModeType(1);
                            List<MaterialNumberAndBatchNoVo> materialNumberAndBatchNoVos = new ArrayList<>();
                            //查询当前明细表中的所有物料号码
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                            String batchNum = "";

                            for (int j = 0; j < stockOutInfoDetailList.size(); j++) {
                                if (j == 0) {
                                    batchNum = stockOutInfoDetailList.get(j).getBatchNumber();
                                } else {
                                    if (!batchNum.equals(stockOutInfoDetailList.get(j).getBatchNumber())) {
                                        batchNum = batchNum + "," + stockOutInfoDetailList.get(j).getBatchNumber();
                                    }
                                }

                                MaterialNumberAndBatchNoVo materialNumberAndBatchNoVo = new MaterialNumberAndBatchNoVo();
                                materialNumberAndBatchNoVo.setMaterialNumber(stockOutInfoDetailList.get(j).getMaterialNumber());
                                materialNumberAndBatchNoVo.setBatchNo(stockOutInfoDetailList.get(j).getBatchNumber());
                                materialNumberAndBatchNoVo.setMaterialCategory(publicGoods.getMaterialCategory());
                                materialNumberAndBatchNoVos.add(materialNumberAndBatchNoVo);
                            }
                            qualityInspectionDocumentVo.setBatchNo(batchNum);

                            insertQuality(sysDocument, qualityInspectionDocumentVo, materialNumberAndBatchNoVos);
                            //修改单据为待检验
                            stockOutInfo1.setWodStatus(4);
                            productionPickingMapper.updateById(stockOutInfo1);
                            return pickingRestDbDto;
                        }
                        //判断是否有交接
                        int docHandoverMark = sysDocument.getDocHandoverMark();
                        //有交接
                        if (docHandoverMark == 1) {
                            //修改单据为待交接
                            stockOutInfo1.setWodStatus(5);
                            productionPickingMapper.updateById(stockOutInfo1);

                        } else {
                            //修改单据为yiwanc
                            stockOutInfo1.setWodStatus(6);


                            //新增线边仓数据
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                            for (StockOutInfoDetail outInfoDetail : stockOutInfoDetailList) {

                                //查询仓库中的数据
                                WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, outInfoDetail.getMaterialNumber()));

                                //往线边仓新增数据
                                LineStock lineStock = new LineStock();
                                lineStock.setMaterialNumber(outInfoDetail.getMaterialNumber());
                                if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                                    lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                                }
                                lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                                lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                                lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                                lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                                lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                                lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                                lineStock.setIntoTheTime(new Date());
                                lineStock.setLineCode(stockOutInfo.getProductionLine());
                                lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

                                lineStockList.add(lineStock);

                            }

                            AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                            if (!"200".equals(ajaxResult.get("code").toString())){
                                throw new GlobalException("出库操作异常");
                            }

                            //删除库存
                            wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue).eq(WmsStockInfo::getWsiMaterialStatus, 5));
                            productionPickingMapper.updateById(stockOutInfo1);
                        }
                    }
                } else {
                    //计划出库重量
                    double allotAmount = stockOutInfo1.getPlannedWeight();
                    //实际出库数量
                    int allotNumOut = stockOutInfo1.getOutgoingNumber();
                    if (allotNumOut >= allotAmount) {
                        //判断是否检验或者交接
                        //判断是否有检验
                        int isDocInspectionMark = sysDocument.getDocInspectionMark();
                        //如果有检验
                        if (isDocInspectionMark == 1) {
                            //生成品质检验单
                            QualityInspectionDocumentVo qualityInspectionDocumentVo = new QualityInspectionDocumentVo();
                            //添加类别，编码，物料类别
                            qualityInspectionDocumentVo.setMaterialCode(stockOutInfo.getMaterialCode());
                            qualityInspectionDocumentVo.setMaterialCategory(publicGoods.getMaterialType());
                            qualityInspectionDocumentVo.setCategory(publicGoods.getMaterialCategory());
                            qualityInspectionDocumentVo.setAssociatedNo(stockOutInfo.getWodDocNum());
                            qualityInspectionDocumentVo.setModeType(1);
                            List<MaterialNumberAndBatchNoVo> materialNumberAndBatchNoVos = new ArrayList<>();
                            //查询当前明细表中的所有物料号码
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                            String batchNum = "";

                            for (int j = 0; j < stockOutInfoDetailList.size(); j++) {
                                if (j == 0) {
                                    batchNum = stockOutInfoDetailList.get(j).getBatchNumber();
                                } else {
                                    if (!batchNum.equals(stockOutInfoDetailList.get(j).getBatchNumber())) {
                                        batchNum = batchNum + "," + stockOutInfoDetailList.get(j).getBatchNumber();
                                    }
                                }

                                MaterialNumberAndBatchNoVo materialNumberAndBatchNoVo = new MaterialNumberAndBatchNoVo();
                                materialNumberAndBatchNoVo.setMaterialNumber(stockOutInfoDetailList.get(j).getMaterialNumber());
                                materialNumberAndBatchNoVo.setBatchNo(stockOutInfoDetailList.get(j).getBatchNumber());
                                materialNumberAndBatchNoVo.setMaterialCategory(publicGoods.getMaterialCategory());
                                materialNumberAndBatchNoVos.add(materialNumberAndBatchNoVo);
                            }
                            qualityInspectionDocumentVo.setBatchNo(batchNum);

                            insertQuality(sysDocument, qualityInspectionDocumentVo, materialNumberAndBatchNoVos);
                            //修改单据为待检验
                            stockOutInfo1.setWodStatus(4);
                            productionPickingMapper.updateById(stockOutInfo1);
                            return pickingRestDbDto;
                        }
                        //判断是否有交接
                        int docHandoverMark = sysDocument.getDocHandoverMark();
                        //有交接
                        if (docHandoverMark == 1) {
                            //修改单据明细为待交接
                            stockOutInfo1.setWodStatus(5);
                            productionPickingMapper.updateById(stockOutInfo1);

                        } else {
                            //修改单据状态为已完成
                            stockOutInfo1.setWodStatus(6);


                            //新增线边仓数据
                            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                            for (StockOutInfoDetail outInfoDetail : stockOutInfoDetailList) {

                                //查询仓库中的数据
                                WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, outInfoDetail.getMaterialNumber()));

                                //往线边仓新增数据
                                LineStock lineStock = new LineStock();
                                lineStock.setMaterialNumber(outInfoDetail.getMaterialNumber());
                                if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                                    lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                                }
                                lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                                lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                                lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                                lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                                lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                                lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                                lineStock.setIntoTheTime(new Date());
                                lineStock.setLineCode(stockOutInfo.getProductionLine());
                                lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

                                lineStockList.add(lineStock);

                            }

                            AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                            if (!"200".equals(ajaxResult.get("code").toString())){
                                throw new GlobalException("批次出库操作异常");
                            }

                            //删除库存
                            wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue).eq(WmsStockInfo::getWsiMaterialStatus, 5));
                            productionPickingMapper.updateById(stockOutInfo1);
                        }
                    }
                }
            }

        } else if ("3".equals(type)) {
            //条码撤销
            StockOutInfo stockOutInfo = productionPickingMapper.selectById(pickingRestDbVo.getId());

            if (stockOutInfo.getWodStatus()!=2&&stockOutInfo.getWodStatus()!=3){
                throw new GlobalException("只能对待出库和出库中的单据进行条码撤销");
            }


            //在明细表中查询是否有此条码
            StockOutInfoDetail stockOutInfoDetail = stockOutInfoDetailMapper.selectOne(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getMaterialNumber, inputValue).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
            if (stockOutInfoDetail == null) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("撤销失败");
                return pickingRestDbDto;
            }


            //修改库存状态为在库
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue));

            wmsStockInfo.setWsiMaterialStatus(2);
            wmsStockInfoMapper.updateById(wmsStockInfo);


            OutboundLog outboundLog = outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, inputValue));
            //删除日志
            outboundLogService.removeById(outboundLog);

            //删除出库明细
            int delete = stockOutInfoDetailMapper.delete(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getMaterialNumber, inputValue));


            BigDecimal out = new BigDecimal(stockOutInfo.getOutgoingWeight());
            BigDecimal bigDecimal = new BigDecimal(wmsStockInfo.getWsiNetWeight());
            BigDecimal outWeight = out.subtract(bigDecimal);
            //修改出库重量
            stockOutInfo.setOutgoingWeight(outWeight.doubleValue());

            //扣除数量
            stockOutInfo.setOutgoingNumber(stockOutInfo.getOutgoingNumber() - 1);

            //实际出库重量
            if ("2".equals(publicGoods.getMaterialUnit())) {

                BigDecimal sj = new BigDecimal(String.valueOf(stockOutInfo.getActualNumber()));
                BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                BigDecimal sjWeight = sj.subtract(bigDecimal1);
                stockOutInfo.setActualNumber(sjWeight.doubleValue());
            }else if ("3".equals(publicGoods.getMaterialUnit())){
                BigDecimal sj = new BigDecimal(String.valueOf(stockOutInfo.getActualNumber()));
                BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(wmsStockInfo.getWsiNetWeight())).divide(new BigDecimal("1000"));
                BigDecimal sjWeight = sj.subtract(bigDecimal1);
                stockOutInfo.setActualNumber(sjWeight.doubleValue());
            } else {
                BigDecimal sj = new BigDecimal(String.valueOf(stockOutInfo.getActualNumber()));
                BigDecimal bigDecimal1 = new BigDecimal("1");
                BigDecimal sjWeight = sj.subtract(bigDecimal1);
                stockOutInfo.setActualNumber(sjWeight.doubleValue());

            }

            int i = productionPickingMapper.updateById(stockOutInfo);
            if (i <= 0) {
                pickingRestDbDto.setMessage("撤销失败");
                pickingRestDbDto.setCode("500");
            }


            //删除品质检验单
            pickingRestDbDto.setMessage("物料号码:" + inputValue + ",净重:" + wmsStockInfo.getWsiNetWeight() + ",数量:" + 1 + "撤销成功");
            pickingRestDbDto.setCode("200");
        }

        return pickingRestDbDto;
    }

    /**
     * 拣货完成
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean finishProduction(Long id) throws Exception {
        //判断当前页面是否有配置送检和交接，如果有则生成品检单

        //获取菜单id
        Long menuId = feignService.getIdByMenuName("生产领料");
        AjaxResult infoDocumentConfigById = systemDocumentFeignService.getInfoDocumentConfigById(menuId);
        SysDocument sysDocument = com.alibaba.fastjson2.JSON.parseObject(JSON.toJSONString(infoDocumentConfigById.get("data")), SysDocument.class);

        //查出调拨信息单
        StockOutInfo stockOutInfo = productionPickingMapper.selectById(id);

        //判断是否有检验
        int docInspectionMark = sysDocument.getDocInspectionMark();
        //如果有检验
        if (docInspectionMark == 1) {

            PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfo.getMaterialCode()));
            //生成品质检验单
            QualityInspectionDocumentVo qualityInspectionDocumentVo = new QualityInspectionDocumentVo();
            //添加类别，编码，物料类别
            qualityInspectionDocumentVo.setMaterialCode(stockOutInfo.getMaterialCode());
            qualityInspectionDocumentVo.setMaterialCategory(publicGoods.getMaterialType());
            qualityInspectionDocumentVo.setCategory(publicGoods.getMaterialCategory());
            qualityInspectionDocumentVo.setAssociatedNo(stockOutInfo.getWodDocNum());
            qualityInspectionDocumentVo.setModeType(1);
            List<MaterialNumberAndBatchNoVo> materialNumberAndBatchNoVos = new ArrayList<>();
            //查询当前明细表中的所有物料号码
            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

            String batchNum = "";

            for (int j = 0; j < stockOutInfoDetailList.size(); j++) {
                if (j == 0) {
                    batchNum = stockOutInfoDetailList.get(j).getBatchNumber();
                } else {
                    if (!batchNum.equals(stockOutInfoDetailList.get(j).getBatchNumber())) {
                        batchNum = batchNum + "," + stockOutInfoDetailList.get(j).getBatchNumber();
                    }
                }

                MaterialNumberAndBatchNoVo materialNumberAndBatchNoVo = new MaterialNumberAndBatchNoVo();
                materialNumberAndBatchNoVo.setMaterialNumber(stockOutInfoDetailList.get(j).getMaterialNumber());
                materialNumberAndBatchNoVo.setBatchNo(stockOutInfoDetailList.get(j).getBatchNumber());
                materialNumberAndBatchNoVo.setMaterialCategory(publicGoods.getMaterialCategory());
                materialNumberAndBatchNoVos.add(materialNumberAndBatchNoVo);
            }
            qualityInspectionDocumentVo.setBatchNo(batchNum);

            insertQuality(sysDocument, qualityInspectionDocumentVo, materialNumberAndBatchNoVos);
            //修改单据状态为待检验
            stockOutInfo.setWodStatus(4);
            return productionPickingMapper.updateById(stockOutInfo) > 0;
        }

        //判断是否有交接
        int docHandoverMark = sysDocument.getDocHandoverMark();
        //有交接
        if (docHandoverMark == 1) {
            //修改单据状态为待交接
            stockOutInfo.setWodStatus(5);
            return productionPickingMapper.updateById(stockOutInfo) > 0;
        }

        //判断是否有超收
        //int docHairMark = sysDocument.getDocHairMark();
        //超收
        //if (docHairMark==1){
        //修改单据状态为已完成
        stockOutInfo.setWodStatus(6);

        //删除库存
        List list = new ArrayList<WmsStockInfo>();

        List<LineStock> lineStockList = new ArrayList<>();
        //新增线边仓数据
        List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
        for (StockOutInfoDetail outInfoDetail : stockOutInfoDetailList) {

            //查询仓库中的数据
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, outInfoDetail.getMaterialNumber()));

            //往线边仓新增数据
            LineStock lineStock = new LineStock();
            lineStock.setMaterialNumber(outInfoDetail.getMaterialNumber());
            if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
            }
            lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
            lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
            lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
            lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
            lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
            lineStock.setStockAlCode(stockOutInfo.getMoNumber());
            lineStock.setIntoTheTime(new Date());
            lineStock.setLineCode(stockOutInfo.getProductionLine());
            lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

            lineStockList.add(lineStock);

        }

        AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

        if (!"200".equals(ajaxResult.get("code").toString())){
            throw new GlobalException("出库操作异常");
        }


        List<StockOutInfoDetail> stockOutInfoDetail3 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

        for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetail3) {
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
            list.add(wmsStockInfo);
        }
        wmsStockInfoMapper.deleteBatchIds(list);

        return productionPickingMapper.updateById(stockOutInfo) > 0;


    }

    /**
     * 拣货撤销
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean repealProduction(Long id) {
        //修改单据状态为待出库
        StockOutInfo stockOutInfo = productionPickingMapper.selectById(id);
        stockOutInfo.setWodStatus(2);
        //实际重量，出库重量，出库数量清空
        stockOutInfo.setActualNumber(0.0);
        stockOutInfo.setOutgoingNumber(0);
        stockOutInfo.setOutgoingWeight(0.0);
        //交接数量，交接重量清空
        stockOutInfo.setOverWeight(0.0);
        stockOutInfo.setOverNum(0);
        productionPickingMapper.updateById(stockOutInfo);

        //查询明细
        List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

        //日志表集合
        List<OutboundLog> outboundLogList = new ArrayList<>();


        //遍历
        for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetailList) {
            //将仓库中的物料全修改为在库
            //修改仓库状态为在库
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
            wmsStockInfo.setWsiMaterialStatus(2);
            wmsStockInfoMapper.updateById(wmsStockInfo);

            OutboundLog outboundLog = outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, wmsStockInfo.getWsiMaterialNumber()));
            outboundLogList.add(outboundLog);
        }
            //删除日志表中的数据
            outboundLogService.removeBatchByIds(outboundLogList);

        //删除品质检验单
        qualityFeginService.removeDoc(stockOutInfo.getWodDocNum());
        //删除所有明细
        int i = stockOutInfoDetailMapper.delete(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

        //删除线边仓数据
        AjaxResult ajaxResult = feignProductionService.deleteBatchLineStock(stockOutInfo.getWodDocNum());

        if (ajaxResult==null){
            throw new GlobalException("服务调用失败");
        }

        if (!"200".equals(ajaxResult.get("code").toString())){
            throw new GlobalException("撤销异常");
        }

        return i > 0;
    }

    /**
     * 出库交接
     *
     * @param pickingRestDbVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public PickingRestHandoverDto overProduction(PickingRestDbVo pickingRestDbVo) {
        //获取步骤
        int step = pickingRestDbVo.getExecutionOrder();
        //获取输入值
        String inputValue = pickingRestDbVo.getInputValue();
        //返回值
        PickingRestHandoverDto pickingRestHandoverDto = new PickingRestHandoverDto();
        //获取菜单id
        Long menuId = feignService.getIdByMenuName("生产领料");
        //交接方式
        AjaxResult infoDocumentConfigById = systemDocumentFeignService.getInfoDocumentConfigById(menuId);
        SysDocument sysDocument = JSON.parseObject(JSON.toJSONString(infoDocumentConfigById.get("data")), SysDocument.class);
        //拿到交接方式
        int jjType = sysDocument.getDocHandoverMethod();

        //根据字典查出单位
        List<SysDictData> unitList = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unitList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        if (step == 1) {


                //校验员工编号
                AjaxResult byUserName = remoteUserService.getByUserName(pickingRestDbVo.getInputValue());
                SysUser userInfo = JSON.parseObject(JSON.toJSONString(byUserName.get("data")), SysUser.class);

                if (userInfo.getUserName() == null) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接人输入有误,请核对后输入");
                    return pickingRestHandoverDto;
                }

            //返回交接人
            pickingRestHandoverDto.setHandoverName(userInfo.getUserName() + "-" + userInfo.getNickName());
            pickingRestHandoverDto.setDocHandoverMethod(jjType);

            if (jjType == 1) {
                pickingRestHandoverDto.setMessage("请输入物料条码");
            } else if (jjType == 2) {
                pickingRestHandoverDto.setMessage("请输入批次号");
            } else if (jjType == 3) {
                StockOutInfo stockOutInfo = productionPickingMapper.selectById(pickingRestDbVo.getId());
                pickingRestDbVo.setInputValue(stockOutInfo.getWodDocNum());
                //查询物料单位
                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfo.getMaterialCode()));

                //判断是否存在明细表中
                List<StockOutInfoDetail> stockOutInfoDetailList1 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, pickingRestDbVo.getInputValue()));
                if (stockOutInfoDetailList1 == null) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接失败");
                    return pickingRestHandoverDto;
                }

                //查询当前单据号在明细中是否存在，且状态为待交接
                List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, pickingRestDbVo.getInputValue()).eq(StockOutInfoDetail::getStatus, 2));
                if (stockOutInfoDetailList.size() == 0) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接失败,请核实后再录入");
                    return pickingRestHandoverDto;
                } else {
                    //查出当前为待交接状态的单据明细,算出总净重和总数量
                    Double sumPiHao = stockOutInfoDetailMapper.getDoc(pickingRestDbVo.getInputValue());
                    //总数量
                    long sumNum = stockOutInfoDetailList.size();

                    //出库重量
                    Double allotAmount = stockOutInfo.getOutgoingWeight();

                    //返回计划/实际
                    //判断是否是kg
                    //(实际交接)
                    Double overWeight = stockOutInfo.getOverWeight();
                    if (overWeight == null) {
                        overWeight = 0.0;
                    }
                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(overWeight));
                    //查询号码在明细中的重量
                    BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(sumPiHao));
                    BigDecimal add = bigDecimal.add(bigDecimal1);

                    stockOutInfo.setOverWeight(add.doubleValue());

                    pickingRestHandoverDto.setQuantityIdentification(allotAmount + "/" + add.toString() + unitMap.get(publicGoods.getMaterialUnit() + ""));


                    //保存交接数量，交接重量
                    Integer overNum = stockOutInfo.getOverNum();
                    if (overNum == null) {
                        overNum = 0;
                    }
                    int jjSum = (int) sumNum;
                    stockOutInfo.setOverNum(overNum + jjSum);

                    //取出关节人
                    String closeUser = stockOutInfo.getCloseMan();
                    if (closeUser == null) {
                        closeUser = "";
                    }
                    String[] split = closeUser.split(",");

                    //获取交接人名称
                    String name = SecurityUtils.getUsername();

                    //定义变量记录交接人是否相等
                    int jj = 0;

                    if (closeUser != null && !"".equals(closeUser)) {
                        for (String s : split) {
                            if (!name.equals(s)) {
                                jj = 1;
                            }
                        }
                    } else {
                        stockOutInfo.setCloseMan(name);
                    }

                    if (jj == 1) {
                        if (closeUser == null || "".equals(closeUser)) {
                            stockOutInfo.setCloseMan(name);
                        } else {
                            stockOutInfo.setCloseMan("," + name);
                        }
                    }


                    //出库/交接
                    pickingRestHandoverDto.setOutHandoverActual(stockOutInfo.getOutgoingNumber() + "/" + stockOutInfo.getOverNum());

                    for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetailList) {
                        //修改物料状态明细为已出库
                        stockOutInfoDetail.setStatus("3");
                        stockOutInfoDetailMapper.updateById(stockOutInfoDetail);
                    }


                    //判断是否所有物料没有待交接的状态
                    List<StockOutInfoDetail> stockOutInfoDetailList2 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getStatus, 2).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                    if (stockOutInfoDetailList2.size() == 0) {
                        //修改单据状态为已完成
                        stockOutInfo.setWodStatus(6);


                        //删除库存
                        List list = new ArrayList<WmsStockInfo>();

                        List<LineStock> lineStockList = new ArrayList<>();
                        List<StockOutInfoDetail> stockOutInfoDetail3 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                        for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetail3) {
                            //查询仓库中的数据
                            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                            //往线边仓新增数据
                            LineStock lineStock = new LineStock();
                            lineStock.setMaterialNumber(stockOutInfoDetail.getMaterialNumber());
                            if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                                lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                            }
                            lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                            lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                            lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                            lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                            lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                            lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                            lineStock.setIntoTheTime(new Date());
                            lineStock.setLineCode(stockOutInfo.getProductionLine());
                            lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

                            lineStockList.add(lineStock);

                            WmsStockInfo wmsStockInfo11 = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                            list.add(wmsStockInfo11);
                        }

                        AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                        if (!"200".equals(ajaxResult.get("code").toString())){
                            throw new GlobalException("出库操作异常");
                        }

                        wmsStockInfoMapper.deleteBatchIds(list);

                    }
                    boolean b = updateById(stockOutInfo);
                    if (!b) {
                        pickingRestHandoverDto.setResultCode("500");
                        pickingRestHandoverDto.setMessage("交接失败");
                        return pickingRestHandoverDto;
                    }

                    //消息提示
                    pickingRestHandoverDto.setMessage("单据号:" + pickingRestDbVo.getInputValue() + ",总净重" + sumPiHao + "数量:" + sumNum + ",交接成功");
                    pickingRestHandoverDto.setResultCode("200");
                }
            }
            pickingRestHandoverDto.setResultCode("200");
            return pickingRestHandoverDto;

        } else {
            //如果是单个物料交接
            if (jjType == 1) {
                //查询当前的出库单信息
                StockOutInfo stockOutInfo = productionPickingMapper.selectById(pickingRestDbVo.getId());

                //查询物料单位
                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfo.getMaterialCode()));


                //查询出库明细
                StockOutInfoDetail stockOutInfoDetail = stockOutInfoDetailMapper.selectOne(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getMaterialNumber, inputValue).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                if (stockOutInfoDetail == null) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接失败");
                    return pickingRestHandoverDto;
                }

                //判断当前物料是否属于待交接
                if (!"2".equals(stockOutInfoDetail.getStatus())) {
                    pickingRestHandoverDto.setMessage("不可重复交接");
                    pickingRestHandoverDto.setResultCode("500");
                    return pickingRestHandoverDto;
                } else {
                    //出库重量
                    Double allotAmount = stockOutInfo.getOutgoingWeight();

                    //(实际交接)
                    Double overWeight = stockOutInfo.getOverWeight();
                    if (overWeight == null) {
                        overWeight = 0.0;
                    }
                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(overWeight));
                    //查询号码在明细中的重量
                    BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(stockOutInfoDetail.getTheWeight()));
                    BigDecimal add = bigDecimal.add(bigDecimal1);

                    stockOutInfo.setOverWeight(add.doubleValue());

                    pickingRestHandoverDto.setQuantityIdentification(allotAmount + "/" + add.toString() + unitMap.get(publicGoods.getMaterialUnit() + ""));

                    Integer overNum = stockOutInfo.getOverNum();
                    if (overNum == null) {
                        overNum = 0;
                    }
                    //保存交接数量，交接重量
                    stockOutInfo.setOverNum(overNum + 1);

                    //取出关节人
                    String closeUser = stockOutInfo.getCloseMan();
                    if (closeUser == null) {
                        closeUser = "";
                    }
                    String[] split = closeUser.split(",");

                    //获取交接人名称
                    String name = SecurityUtils.getUsername();

                    //定义变量记录交接人是否相等
                    int jj = 0;

                    if (closeUser != null && !"".equals(closeUser)) {
                        for (String s : split) {
                            if (!name.equals(s)) {
                                jj = 1;
                            }
                        }
                    } else {
                        stockOutInfo.setCloseMan(name);
                    }


                    if (jj == 1) {
                        stockOutInfo.setCloseMan("," + name);
                    }
                    stockOutInfo.setCloseTime(new Date());

                    //出库/交接
                    pickingRestHandoverDto.setOutHandoverActual(stockOutInfo.getOutgoingNumber() + "/" + stockOutInfo.getOverNum());

                    //修改物料状态明细为已出库
                    stockOutInfoDetail.setStatus("3");
                    stockOutInfoDetailMapper.updateById(stockOutInfoDetail);


                    //判断是否所有物料没有待交接的状态
                    List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getStatus, 2).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                    if (stockOutInfoDetailList.size() == 0) {
                        //修改单据状态为已完成
                        stockOutInfo.setWodStatus(6);



                        //删除库存
                        List list = new ArrayList<WmsStockInfo>();

                        List<LineStock> lineStockList = new ArrayList<>();
                        List<StockOutInfoDetail> stockOutInfoDetail3 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                        for (StockOutInfoDetail stockOutInfoDetail11 : stockOutInfoDetail3) {
                            //查询仓库中的数据
                            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                            //往线边仓新增数据
                            LineStock lineStock = new LineStock();
                            lineStock.setMaterialNumber(stockOutInfoDetail11.getMaterialNumber());
                            if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                                lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                            }
                            lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                            lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                            lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                            lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                            lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                            lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                            lineStock.setIntoTheTime(new Date());
                            lineStock.setLineCode(stockOutInfo.getProductionLine());
                            lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

                            lineStockList.add(lineStock);

                            WmsStockInfo wmsStockInfo11 = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                            list.add(wmsStockInfo11);
                        }

                        AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                        if (!"200".equals(ajaxResult.get("code").toString())){
                            throw new GlobalException("出库操作异常");
                        }

                        wmsStockInfoMapper.deleteBatchIds(list);
                    }


                    boolean b = updateById(stockOutInfo);
                    if (!b) {
                        pickingRestHandoverDto.setMessage("交接失败");
                        pickingRestHandoverDto.setResultCode("500");
                    }

                    //消息提示
                    pickingRestHandoverDto.setMessage("物料号码:" + pickingRestDbVo.getInputValue() + ",净重" + stockOutInfoDetail.getTheWeight() + "数量:1,交接成功");
                    pickingRestHandoverDto.setResultCode("200");
                }
            } else if (jjType == 2) {
                StockOutInfo stockOutInfo = productionPickingMapper.selectById(pickingRestDbVo.getId());

                //查询物料单位
                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfo.getMaterialCode()));

                //判断是否存在明细表中
                List<StockOutInfoDetail> stockOutInfoDetailList1 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getBatchNumber, pickingRestDbVo.getInputValue()).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                if (stockOutInfoDetailList1 == null) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接失败");
                    return pickingRestHandoverDto;
                }

                //查询当前批号在明细中是否存在，且状态为待交接
                List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getBatchNumber, pickingRestDbVo.getInputValue()).eq(StockOutInfoDetail::getStatus, 2).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));
                if (stockOutInfoDetailList.size() == 0) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("不可重复交接");
                    return pickingRestHandoverDto;
                } else {
                    //查出当前为待交接状态的批次，算出总净重和总数量
                    Double sumPiHao = stockOutInfoDetailMapper.getPiHao(pickingRestDbVo.getInputValue());
                    //总数量
                    long sumNum = stockOutInfoDetailList.size();

                    //出库重量
                    Double allotAmount = stockOutInfo.getOutgoingWeight();

                    //返回计划/实际
                    Double overWeight = stockOutInfo.getOverWeight();
                    if (overWeight == null) {
                        overWeight = 0.0;
                    }
                    //(实际交接)
                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(overWeight));
                    //查询号码在明细中的重量
                    BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(sumPiHao));
                    BigDecimal add = bigDecimal.add(bigDecimal1);

                    stockOutInfo.setOverWeight(add.doubleValue());

                    pickingRestHandoverDto.setQuantityIdentification(allotAmount + "/" + add.toString() + unitMap.get(publicGoods.getMaterialUnit() + ""));


                    //保存交接数量，交接重量
                    Integer overNum = stockOutInfo.getOverNum();
                    if (overNum == null) {
                        overNum = 0;
                    }
                    int jjSum = (int) sumNum;
                    stockOutInfo.setOverNum(overNum + jjSum);

                    //取出关节人
                    String closeUser = stockOutInfo.getCloseMan();
                    if (closeUser == null) {
                        closeUser = "";
                    }
                    String[] split = closeUser.split(",");

                    //获取交接人名称
                    String name = SecurityUtils.getUsername();

                    //定义变量记录交接人是否相等
                    int jj = 0;

                    if (closeUser != null && !"".equals(closeUser)) {
                        for (String s : split) {
                            if (!name.equals(s)) {
                                jj = 1;
                            }
                        }
                    } else {
                        stockOutInfo.setCloseMan(name);
                    }

                    if (jj == 1) {
                        if (closeUser == null || "".equals(closeUser)) {
                            stockOutInfo.setCloseMan(name);
                        } else {
                            stockOutInfo.setCloseMan("," + name);
                        }
                    }
                    stockOutInfo.setCloseTime(new Date());

                    //出库/交接
                    pickingRestHandoverDto.setOutHandoverActual(stockOutInfo.getOutgoingNumber() + "/" + stockOutInfo.getOverNum());

                    for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetailList) {
                        //修改物料状态明细为已出库
                        stockOutInfoDetail.setStatus("3");
                    }
                    stockInfoDetailService.updateBatchById(stockOutInfoDetailList);

                    //判断是否所有物料没有待交接的状态
                    List<StockOutInfoDetail> stockOutInfoDetailList2 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getStatus, 2).eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                    if (stockOutInfoDetailList2.size() == 0) {
                        //修改单据状态为已完成
                        stockOutInfo.setWodStatus(6);
                        //删除库存
                        List list = new ArrayList<WmsStockInfo>();

                        List<LineStock> lineStockList = new ArrayList<>();
                        List<StockOutInfoDetail> stockOutInfoDetail3 = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, stockOutInfo.getWodDocNum()));

                        for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetail3) {
                            //查询仓库中的数据
                            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                            //往线边仓新增数据
                            LineStock lineStock = new LineStock();
                            lineStock.setMaterialNumber(stockOutInfoDetail.getMaterialNumber());
                            if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                                lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                            }
                            lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                            lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                            lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                            lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                            lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                            lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                            lineStock.setIntoTheTime(new Date());
                            lineStock.setLineCode(stockOutInfo.getProductionLine());
                            lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

                            lineStockList.add(lineStock);

                            WmsStockInfo wmsStockInfo11 = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                            list.add(wmsStockInfo11);
                        }

                        AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

                        if (!"200".equals(ajaxResult.get("code").toString())){
                            throw new GlobalException("出库操作异常");
                        }

                        wmsStockInfoMapper.deleteBatchIds(list);
                    }
                    boolean b = updateById(stockOutInfo);
                    if (!b) {
                        pickingRestHandoverDto.setResultCode("500");
                        pickingRestHandoverDto.setMessage("交接失败");
                        return pickingRestHandoverDto;
                    }

                    //消息提示
                    pickingRestHandoverDto.setMessage("批次号:" + pickingRestDbVo.getInputValue() + ",总净重" + sumPiHao + "数量:" + sumNum + ",交接成功");
                    pickingRestHandoverDto.setResultCode("200");
                }
            } else if (jjType == 3) {
                pickingRestHandoverDto.setResultCode("500");
                pickingRestHandoverDto.setMessage("请勿重复交接");
            }
        }
        return pickingRestHandoverDto;
    }

    /**
     * 生产领料自动新增
     *
     * @param feginProductionPickingVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addAutoProduction(FeginProductionPickingVo feginProductionPickingVo) throws Exception {
        List<ProductionPickingRelationVo> bomList = feginProductionPickingVo.getBomList();

        AjaxResult ajaxResult = feignService.getModelingLineInfo(feginProductionPickingVo.getProductionLine());
        SysLineDto sysLineDto = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), SysLineDto.class);

        boolean b = false;

        if (bomList.size() > 0) {
            for (ProductionPickingRelationVo entity : bomList) {

                //生产领料信息
                //BeanUtils.copyProperties(feginProductionPickingVo, stockOutInfo,new String[]{"id"});
                String sn = feignService.getAuthorityCoding("warehouse:outbound:producfield:list");
                if (sn == null) {
                    throw new GlobalException("该单据未进行配置,无法生成单据编码");
                }
                StockOutInfo stockOutInfo = new StockOutInfo();
                stockOutInfo.setWodStatus(1)
                        .setMaterialCode(entity.getMaterialCode())
                        .setProductionLine(feginProductionPickingVo.getProductionLine())
                        .setProductionLineName(sysLineDto.getLineName())
                        .setTransceiverType(1)
                        .setDocumentType(DocumentTypeEnum.PRODUCTION_PICKING.getCode())
                        .setGenerationMode(GenerationMethodEnum.AUTO_GENERATE.getCode())
                        .setWodDocNum(sn)
                        .setCreateUser(SecurityUtils.getUsername())
                        .setCreateTime(new Date())
                        .setDateDelivery(new Date())
                        .setMoNumber(feginProductionPickingVo.getMoNumber())
                        .setPlannedWeight(entity.getPlannedWeight())
                        .setDeptId(SecurityUtils.getDeptId());

                b = save(stockOutInfo);
            }
        }else {
            throw new GlobalException("生成生产领料单失败");
        }
        return b;
    }

    /**
     * 脱脂模块生成生产领料单(fegin调用)
     *
     * @param feginProductionPickingVo
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addAutoProductionByDegreas(FeginProductionPickingVo feginProductionPickingVo) throws Exception {
        List<StockOutInfoDetail> list = feginProductionPickingVo.getList();
        StockOutInfo stockOutInfo = new StockOutInfo();
        AjaxResult ajaxResult = feignService.getModelingLineInfo(feginProductionPickingVo.getProductionLine());
        SysLineDto sysLineDto = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), SysLineDto.class);
        if (list.size() > 0) {
            for (StockOutInfoDetail entity : list) {

                //生产领料信息
                BeanUtils.copyProperties(feginProductionPickingVo, stockOutInfo);
                String sn = feignService.getAuthorityCoding("warehouse:outbound:producfield:list");
                if (sn == null) {
                    throw new GlobalException("该单据未进行配置,无法生成单据编码");
                }
                stockOutInfo.setWodStatus(1)
                        .setMaterialCode(entity.getMaterialCode())
                        .setProductionLineName(sysLineDto.getLineName())
                        .setTransceiverType(1)
                        .setDocumentType(DocumentTypeEnum.PRODUCTION_PICKING.getCode())
                        .setGenerationMode(GenerationMethodEnum.AUTO_GENERATE.getCode())
                        .setWodDocNum(sn)
                        .setCreateUser(SecurityUtils.getUsername())
                        .setCreateTime(new Date())
                        .setDeptId(SecurityUtils.getDeptId());

                boolean b = save(stockOutInfo);
                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, stockOutInfo.getMaterialCode()));

                if (b) {
                    FeedRecord feedRecord = new FeedRecord();
                    feedRecord.setFeedOrderNumber(stockOutInfo.getMoNumber());
                    feedRecord.setLineCode(feginProductionPickingVo.getProductionLine());
                    feedRecord.setMaterialCode(stockOutInfo.getMaterialCode());
                    feedRecord.setMaterialName(publicGoods.getMaterialName());
                    feedRecord.setMaterialSpec(publicGoods.getMaterialSpec());
                    feedRecord.setDeliveryWeight(stockOutInfo.getPlannedWeight());
                    feedRecord.setInvestedWeight(0);
                    feedRecord.setFeedType("2");
                    feedRecord.setCreateBy(SecurityUtils.getUsername());
                    feignProductionService.add(feedRecord);
//                    //生成对应的明细数据
//                    StockOutInfoDetail stockOutInfoDetail = new StockOutInfoDetail();
//                    stockOutInfoDetail.setWodDocNum(stockOutInfo.getWodDocNum())
//                            .setMaterialCode(entity.getMaterialCode())
//                            .setStatus("1")
//                            .setMaterialNumber(feignService.splitList("CGRKDYNUM"));
//                    return stockInfoDetailService.save(stockOutInfoDetail);
                }
            }
        }else {
            throw new GlobalException("生成生产领料单失败");
        }
        return true;
    }

    /**
     * 查看当前制令单对应的领料明细是否为空
     *
     * @param feedVo
     * @return
     */
    @Override
    public boolean getMoNumber(FeedVo feedVo) {
        long count = productionPickingMapper.getMoNumber(feedVo);
        if (count > 0) {
            return true;
        } else {
            throw new GlobalException("调用失败");
        }
    }

    /**
     * 拣货提示
     *
     * @param id
     * @return
     */
    @Override
    public SchemeDto point(Long id) {
        StockOutInfo byId = getById(id);
        SchemeVo schemeVo = new SchemeVo();
        schemeVo.setMaterialCode(byId.getMaterialCode());
        schemeVo.setAssociatedDetails("1");
        return pickingSchemeService.getSchemeData(schemeVo);
    }

    /**
     * 品质检验
     *
     * @param sysDocument
     * @param qualityInspectionDocumentVo
     * @param list
     */
    @Override
    public void insertQuality(SysDocument sysDocument, QualityInspectionDocumentVo qualityInspectionDocumentVo, List<MaterialNumberAndBatchNoVo> list) throws Exception {

        List<SysDocumentCheckDto> documentCheckDtoList = sysDocument.getDocumentCheckDtoList();

        //检测阶别
        List<SysDictData> rankArray = DictUtils.getDictCache("item_rank");
        Map<String, String> rankMap = rankArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (SysDocumentCheckDto sysDocumentCheckDto : documentCheckDtoList) {
            if ((sysDocumentCheckDto.getCheckType()) == (qualityInspectionDocumentVo.getCategory())) {
                //生成品质检验单
                qualityInspectionDocumentVo.setItemRank(sysDocumentCheckDto.getCheckSubmit());//检测阶别：2:Fai
                //qualityInspectionDocumentVo.setInspectionSheetNo(rankMap.get(sysDocumentCheckDto.getCheckSubmit()) + "-" + feignService.splitList("JYDJ"));//检测单号
                qualityInspectionDocumentVo.setInspectDept(SecurityUtils.getDeptId());
                qualityInspectionDocumentVo.setMaterialNumberAndBatchNo(list);
            }
        }
        boolean b = qualityFeginService.addWares(qualityInspectionDocumentVo);


        if (!b){
            throw new GlobalException("请先配置检验方案");
        }

    }

    /**
     * 品质修改仓库物料明细状态Feign
     *
     * @param updateDocVo
     * @return
     */
    @Override
    public boolean updateStatus(UpdateDocVo updateDocVo) {
        //获取菜单id
        Long menuId = feignService.getIdByMenuName("生产领料");
        //交接方式
        AjaxResult infoDocumentConfigById = systemDocumentFeignService.getInfoDocumentConfigById(menuId);
        SysDocument sysDocument = JSON.parseObject(JSON.toJSONString(infoDocumentConfigById.get("data")), SysDocument.class);
        //交接方式
        int docHandoverMethod = sysDocument.getDocHandoverMark();

        //判断是否有交接

        //如果有交接，修改单据状态和物料明细状态为代交接
        if (docHandoverMethod == 1) {
            StockOutInfo stockOutInfo = productionPickingMapper.selectOne(new QueryWrapper<StockOutInfo>().lambda().eq(StockOutInfo::getWodDocNum, updateDocVo.getDocNum()));
            stockOutInfo.setWodStatus(5);//待交接
            updateById(stockOutInfo);
            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, updateDocVo.getDocNum()));



            for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetailList) {
                stockOutInfoDetail.setStatus("2");
            }
            return stockInfoDetailService.updateBatchById(stockOutInfoDetailList);

        } else {
            StockOutInfo stockOutInfo = productionPickingMapper.selectOne(new QueryWrapper<StockOutInfo>().lambda().eq(StockOutInfo::getWodDocNum, updateDocVo.getDocNum()));
            stockOutInfo.setWodStatus(6);//已完成
            updateById(stockOutInfo);

            List<WmsStockInfo> wmsStockInfoList = new ArrayList<>();


            //删除库存
            List list = new ArrayList<WmsStockInfo>();

            List<LineStock> lineStockList = new ArrayList<>();


            List<StockOutInfoDetail> stockOutInfoDetailList = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, updateDocVo.getDocNum()));
            for (StockOutInfoDetail stockOutInfoDetail : stockOutInfoDetailList) {
                stockOutInfoDetail.setStatus("3");
                WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, stockOutInfoDetail.getMaterialNumber()));
                //往线边仓新增数据
                LineStock lineStock = new LineStock();
                lineStock.setMaterialNumber(stockOutInfoDetail.getMaterialNumber());
                if (!StringUtils.isEmpty(wmsStockInfo.getWsiMaterialGrade())) {
                    lineStock.setMaterialGrade(Integer.parseInt(wmsStockInfo.getWsiMaterialGrade()));
                }
                lineStock.setMaterialCode(wmsStockInfo.getWsiMaterialCode());
                lineStock.setStockBatch(wmsStockInfo.getWsiMaterialBatch());
                lineStock.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                lineStock.setNetWeight(wmsStockInfo.getWsiNetWeight());
                lineStock.setWareAlCode(stockOutInfo.getWodDocNum());//生产领料单号
                lineStock.setStockAlCode(stockOutInfo.getMoNumber());
                lineStock.setIntoTheTime(new Date());
                lineStock.setLineCode(stockOutInfo.getProductionLine());
                lineStock.setFreezeMark(Integer.parseInt(wmsStockInfo.getWsiFreezeInfo()));

                lineStockList.add(lineStock);


                wmsStockInfoList.add(wmsStockInfo);
            }


            AjaxResult ajaxResult = feignProductionService.addBatchLineStock(lineStockList);

            if (!"200".equals(ajaxResult.get("code").toString())){
                throw new GlobalException("出库操作异常");
            }

            wmsStockInfoMapper.deleteBatchIds(list);
            wmsStockInfoService.removeBatchByIds(wmsStockInfoList);
            return stockInfoDetailService.updateBatchById(stockOutInfoDetailList);
        }
    }

    @Override
    public List getPdaList(String number) {
        if ("1".equals(number)) {
            return getListPda(new ProductionPickingVo());
        } else if ("2".equals(number)) {
            return pickingOutsourceService.getListPda(new PickingOutsourceVo());
        } else if ("3".equals(number)) {
            return pickingSaleService.getListPda(new PickingSaleVo());
        } else if ("4".equals(number)) {
            return pickingCompleteService.getListPda(new PickingCompleteVo());
        } else if ("5".equals(number)) {
            return pickingPurchaseService.getListPda(new PickingPurchaseVo());
        } else if ("6".equals(number)) {
            return pickingReturnsService.getListPda(new PickingReturnsVo());
        } else if ("7".equals(number)) {
            return pickingRestService.getListPda(new PickingRestVo());
        }

        return null;

    }

    @Override
    public GetPdaDto getPdaDetail(GetPdaVo getPdaVo) {
        GetPdaDto getPdaDto = new GetPdaDto();
        if ("1".equals(getPdaVo.getNumber())) {
            StockOutInfoDto view = view(getPdaVo.getId());
            getPdaDto.setOutboundType("生产领料");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            getPdaDto.setMaterialUnit(view.getMaterialUnit());
            getPdaDto.setPlannedWeight(view.getPlannedWeight());
            getPdaDto.setActualNumber(view.getActualNumber());
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        } else if ("2".equals(getPdaVo.getNumber())) {
            PickingOutsourceDto view = pickingOutsourceService.view(getPdaVo.getId());
            getPdaDto.setOutboundType("委外发货");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            getPdaDto.setMaterialUnit(view.getMaterialUnit());
            getPdaDto.setPlannedWeight(view.getPlannedWeight());
            getPdaDto.setActualNumber(view.getActualNumber());
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = pickingOutsourceService.point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        } else if ("3".equals(getPdaVo.getNumber())) {
            PickingSaleDto view = pickingSaleService.view(getPdaVo.getId());
            getPdaDto.setOutboundType("销售发货");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            getPdaDto.setMaterialUnit(view.getMaterialUnit());
            getPdaDto.setPlannedWeight(view.getPlannedWeight());
            getPdaDto.setActualNumber(view.getActualNumber());
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = pickingSaleService.point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        } else if ("4".equals(getPdaVo.getNumber())) {
            PickingCompleteDto view = pickingCompleteService.view(getPdaVo.getId());
            getPdaDto.setOutboundType("返工出库");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            if(view.getPlannedWeight() != null){
                getPdaDto.setPlannedWeight(Double.parseDouble(view.getPlannedWeight() + ""));
            }
            if(view.getOutgoingNumber() != null){
                getPdaDto.setActualNumber(Double.parseDouble(view.getOutgoingNumber() +""));
            }
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = pickingCompleteService.point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        } else if ("5".equals(getPdaVo.getNumber())) {
            PickingPurchaseDto view = pickingPurchaseService.view(getPdaVo.getId());
            getPdaDto.setOutboundType("采购退货");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            if(view.getPlannedWeight() != null){
                getPdaDto.setPlannedWeight(Double.parseDouble(view.getPlannedWeight() + ""));
            }
            if(view.getOutgoingNumber() != null){
                getPdaDto.setActualNumber(Double.parseDouble(view.getOutgoingNumber() +""));
            }
//            getPdaDto.setPlannedWeight(Double.parseDouble(view.getPlannedWeight() + ""));
//            getPdaDto.setActualNumber(Double.parseDouble(view.getOutgoingNumber()));
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = pickingPurchaseService.point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        } else if ("6".equals(getPdaVo.getNumber())) {
            PickingReturnsDto view = pickingReturnsService.view(getPdaVo.getId());
            getPdaDto.setOutboundType("委外退货");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            if(view.getPlannedWeight() != null){
                getPdaDto.setPlannedWeight(Double.parseDouble(view.getPlannedWeight() + ""));
            }
            if(view.getOutgoingNumber() != null){
                getPdaDto.setActualNumber(Double.parseDouble(view.getOutgoingNumber() +""));
            }
//            getPdaDto.setPlannedWeight(Double.parseDouble(view.getPlannedWeight() + ""));
//            getPdaDto.setActualNumber(Double.parseDouble(view.getOutgoingNumber()));
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = pickingReturnsService.point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        } else if ("7".equals(getPdaVo.getNumber())) {
            PickingRestDto view = pickingRestService.view(getPdaVo.getId());
            getPdaDto.setOutboundType("其他出库");
            getPdaDto.setWodDocNum(view.getWodDocNum());
            getPdaDto.setMaterialCode(view.getMaterialCode());
            getPdaDto.setMaterialName(view.getItemName());
            getPdaDto.setMaterialUnit(view.getMaterialUnit());
            getPdaDto.setPlannedWeight(view.getPlannedWeight());
            getPdaDto.setActualNumber(view.getActualNumber());
            getPdaDto.setOutgoingNumber(view.getOutgoingNumber());
            String combinationName = pickingRestService.point(getPdaVo.getId()).getCombinationName();
            getPdaDto.setCombinationName(combinationName);
            getPdaDto.setId(getPdaVo.getId());
        }
        return getPdaDto;
    }

    @Override
    public boolean getPdaFinish(GetPdaVo getPdaVo) throws Exception {
        Long id = getPdaVo.getId();
        String number = getPdaVo.getNumber();
        if ("1".equals(number)) {
            return finishProduction(id);
        } else if ("2".equals(number)) {
            return pickingOutsourceService.finishProduction(id);
        } else if ("3".equals(number)) {
            return pickingSaleService.finishProduction(id);
        } else if ("4".equals(number)) {
            return pickingCompleteService.finishProduction(id);
        } else if ("5".equals(number)) {
            return pickingPurchaseService.subcontractingPurchase(id);
        } else if ("6".equals(number)) {
            return pickingReturnsService.subcontractingPicking(id);
        } else if ("7".equals(number)) {
            return pickingRestService.pickingRestCompleted(id);
        }
        return true;

    }

    @Override
    public boolean getCeX(GetPdaVo getPdaVo) {
        Long id = getPdaVo.getId();
        String number = getPdaVo.getNumber();
        if ("1".equals(number)) {
            return repealProduction(id);
        } else if ("2".equals(number)) {
            return pickingOutsourceService.repealProduction(id);
        } else if ("3".equals(number)) {
            return pickingSaleService.repealProduction(id);
        } else if ("7".equals(number)) {
            return pickingRestService.pickingRestRepeal(id);
        }
        return true;

    }

    /**
     * 全局拣货提示
     *
     * @param schemePdaVo
     * @return
     */
    @Override
    public SchemePdaDto getSchemePdaInfo(SchemePdaVo schemePdaVo) {

        //拣货提示
        SchemePdaDto schemePdaDto = new SchemePdaDto();

        //类型
        String type = schemePdaVo.getType();

        //id
        Long id = schemePdaVo.getId();


        //生产领料
        if ("1".equals(type)) {
            SchemeDto point = point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else if ("2".equals(type)) {
            //委外发货单
            SchemeDto point = pickingOutsourceService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else if ("3".equals(type)) {
            //销售发货单
            SchemeDto point = pickingSaleService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else if ("4".equals(type)) {
            //其他出库单
            SchemeDto point = pickingRestService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else if ("5".equals(type)) {
            //调拨单
            SchemeDto point = allotManagementService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else if ("6".equals(type)) {
            //返工出库
            SchemeDto point = pickingCompleteService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else if ("7".equals(type)) {
            //采购退货
            SchemeDto point = pickingPurchaseService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        } else {
            //委外退货
            SchemeDto point = pickingReturnsService.point(id);
            schemePdaDto.setPickingPrompt(point.getCombinationName());
            return schemePdaDto;
        }
    }


    /**
     * 脱脂制令单修改时修改相关生产制令单（fegin调用）
     *
     * @param degreasByUpdateVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateByDegreas(DegreasByUpdateVo degreasByUpdateVo) throws Exception {

        //根据脱脂制令单获取相关单据
        List<StockOutInfo> stockOutInfos = productionPickingMapper.selectList(new QueryWrapper<StockOutInfo>().lambda().eq(StockOutInfo::getMoNumber, degreasByUpdateVo.getDegreasOrderNumber()));

        for (StockOutInfo entity : stockOutInfos) {

            //若修改了计划重量（导致计算的配料需求量发生变化），则保存后，同步修改生产领料单（关联的生产领料单状态为“待确认”时同步修改）
            double planWeight = entity.getPlannedWeight();
            double planWeight1 = degreasByUpdateVo.getPlanWeight();
            BigDecimal data1 = new BigDecimal(planWeight);
            BigDecimal data2 = new BigDecimal(planWeight1);
            if (data1.compareTo(data2) != 0 && entity.getWodStatus() == 1) {
                //修改状态为待确认的生产领料单中的计划重量
                entity.setPlannedWeight(degreasByUpdateVo.getPlanWeight());
                updateById(entity);
            }
            //若关联的生产领料单已经确认，但未出库（即“待出库”状态）则关结该生产领料单，在制令单修改保存后，生成新的生产领料单
            if (entity.getWodStatus() == 2) {
                entity.setWodStatus(7);
                updateById(entity);
                //生成新的生产领料单
                StockOutInfo stockOutInfo = new StockOutInfo();
                String sl = feignService.splitList("SL");
                stockOutInfo
                        .setProductionLine(degreasByUpdateVo.getLineCode())
                        .setMoNumber(degreasByUpdateVo.getDegreasOrderNumber())
                        .setMaterialCode(entity.getMaterialCode())
                        .setProductionLineName(degreasByUpdateVo.getProductionLineName())
                        .setPlannedWeight(degreasByUpdateVo.getPlanWeight())
                        .setWodStatus(1)
                        .setTransceiverType(1)
                        .setDocumentType(DocumentTypeEnum.PRODUCTION_PICKING.getCode())
                        .setGenerationMode(GenerationMethodEnum.AUTO_GENERATE.getCode())
                        .setWodDocNum(sl)
                        .setCreateUser(SecurityUtils.getUsername())
                        .setCreateTime(new Date())
                        .setDeptId(SecurityUtils.getDeptId());
                save(stockOutInfo);
                StockOutInfoDetail stockOutInfoDetail = new StockOutInfoDetail();
                stockOutInfoDetail.setWodDocNum(stockOutInfo.getWodDocNum())
                        .setMaterialCode(entity.getMaterialCode())
                        .setStatus("1")
                        .setMaterialNumber(feignService.splitList("CGRKDYNUM"));
                stockInfoDetailService.save(stockOutInfoDetail);
            }
            //若关联的生产领料单已经出库或者已完成，则在制令单修改保存后，生成新的生产领料单，原生产领料单由生产人员手动处理
            if (entity.getWodStatus() == 3 || entity.getWodStatus() == 6) {
                StockOutInfo stockOutInfo = new StockOutInfo();
                String sn = feignService.getAuthorityCoding("warehouse:outbound:producfield:list");
                if (sn == null) {
                    throw new GlobalException("该单据未进行配置,无法生成单据编码");
                }
                stockOutInfo
                        .setProductionLine(degreasByUpdateVo.getLineCode())
                        .setMoNumber(degreasByUpdateVo.getDegreasOrderNumber())
                        .setMaterialCode(entity.getMaterialCode())
                        .setPlannedWeight(degreasByUpdateVo.getPlanWeight())
                        .setProductionLineName(degreasByUpdateVo.getProductionLineName())
                        .setWodStatus(1)
                        .setTransceiverType(1)
                        .setDocumentType(DocumentTypeEnum.PRODUCTION_PICKING.getCode())
                        .setGenerationMode(GenerationMethodEnum.AUTO_GENERATE.getCode())
                        .setWodDocNum(sn)
                        .setCreateUser(SecurityUtils.getUsername())
                        .setCreateTime(new Date())
                        .setDeptId(SecurityUtils.getDeptId());
                save(stockOutInfo);
                StockOutInfoDetail stockOutInfoDetail = new StockOutInfoDetail();
                stockOutInfoDetail.setWodDocNum(stockOutInfo.getWodDocNum())
                        .setMaterialCode(entity.getMaterialCode())
                        .setStatus("1")
                        .setMaterialNumber(feignService.splitList("CGRKDYNUM"));
                stockInfoDetailService.save(stockOutInfoDetail);
            }
        }


        return updateBatchById(stockOutInfos);
    }

    /**
     * 脱脂制令单删除相关生产制令单(fegin调用)
     *
     * @param degreasOrderNumber
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByDegreas(String degreasOrderNumber) {
        //对应的生产领料单若为“待确认”，则删除生产领料单，若为“待出库”，则关结，若已出库，则由生产人员手动处理
        List<StockOutInfo> stockOutInfos = productionPickingMapper.selectList(new QueryWrapper<StockOutInfo>().lambda().eq(StockOutInfo::getMoNumber, degreasOrderNumber));
        for (StockOutInfo entity : stockOutInfos) {
            if (entity.getWodStatus() == 1) {
                //查询明细删除
                List<StockOutInfoDetail> stockOutInfoDetails = stockOutInfoDetailMapper.selectList(new QueryWrapper<StockOutInfoDetail>().lambda().eq(StockOutInfoDetail::getWodDocNum, entity.getWodDocNum()));
                boolean b = stockInfoDetailService.removeByIds(stockOutInfoDetails);
                if (b) {
                    removeById(entity);
                }
            }
        }
    }

    /**
     * 水刺制令单号查询数据（fegin）
     */
    @Override
    public List<StockOutInfoDto> spunlaceNumber(String spunlaceOrderNumber) {

        return productionPickingMapper.getStockOutInfoList(spunlaceOrderNumber);
    }

}
